;; io.scm - (c) rohan drape, 2005

;; Overwrite `file-name' if exists.

(define (call-with-output-file* file-name proc)
  (unlink* file-name)
  (call-with-output-file file-name proc))

(define (with-output-to-file* file-name proc)
  (unlink* file-name)
  (with-output-to-file file-name proc))

(define (open-output-file* file-name)
  (unlink* file-name)
  (open-output-file file-name))

;; Sequence the R5RS procedures 'display' and 'newline'.  If `port' is
;; given it is the output port, otherwise the current output port is
;; used.

(define (display* object . port)
  (let ((port_ (if (null? port) (current-output-port) (car port))))
    (display object port_)
    (newline port_)))

;; Print the string `message', followed by any `arguments' to the
;; current error port.

(define (inform message . arguments)
  (let ((p (current-error-port)))
    (display message p)
    (if (not (null? arguments))
	(begin
	  (display " " p)
	  (for-each (lambda (e) 
		      (display (format "~a " e) p))
		    arguments)))
    (newline p)))

;; Read a file as a byte vector.

(define (file->u8vector file-name)
  (let* ((port (open-input-file file-name))
	 (u8vector (read-u8vector (file-size file-name) port)))
    (close-input-port port)
    u8vector))

